home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / lan / printqv1.zip / PRINTQ.C < prev    next >
C/C++ Source or Header  |  1995-11-03  |  11KB  |  315 lines

  1. #include "printq.h"
  2.  
  3. int maincounter=0, wnum=0, twoormore=NO, SHOWONLY=NO;
  4. Winrec buffer[MAXWINDOW];
  5.  
  6. void main(int argc, char *argv[])
  7. { int servercount, serversattached, loop;
  8. //  unsigned x=1,y=1;
  9.   char *achar, *achar2;
  10.  
  11.   _setcursortype(_NOCURSOR);
  12.   clrscr();
  13.   if (argc = 2)
  14.     {  if (strcmp(strupr(argv[1]),"/?") == 0)
  15.        {  displayhelp();
  16.           _setcursortype(_NORMALCURSOR);
  17.           exit(1);
  18.        }
  19.        if (strcmp(strupr(argv[1]),"/Q") == 0)
  20.          SHOWONLY = YES;
  21.     }
  22.   initmainnwcalls();
  23.   printf("Scanning for server(s). . .");
  24.   servercount = scanforservers();
  25.   printf("DONE. . .%d found\nScanning for attached servers. . .",servercount);
  26.   for (loop=0;loop<=servercount;loop++)
  27.     serversattached = getserverinfo(loop);
  28.   printf("DONE. . .\nAttached to %d servers.\n",serversattached);
  29.   for (loop=0;loop<serversattached;loop++)
  30.     GetQueues(loop);
  31. //  checklpts();
  32.   if (SHOWONLY == NO)
  33.   { clrscr();
  34.     while (!kbhit())
  35.       { for (loop=0;loop<maincounter;loop++)
  36.           ScanQueues(loop);
  37.       }
  38.   } // if
  39.   _setcursortype(_NORMALCURSOR);
  40. } // main
  41.  
  42. // init the 3 main nwcalls
  43. void initmainnwcalls()
  44. { WORD nwrc;
  45.  
  46.     nwrc = (NWCallsInit(NULL, NULL));
  47.     if (nwrc != 0x0000)
  48.       {  printf("\nNWCallsInit: failed %04x",nwrc);
  49.           getch();  exit(1);
  50.       }
  51.  
  52.     nwrc = (NWGetDefaultConnectionID(&connHandle));
  53.     if (nwrc != 0x0000)
  54.       {  printf("\nNWGetDefaultConnectionID: failed %04x",nwrc);
  55.           getch();  exit(1);
  56.       }
  57.  
  58.     nwrc = (NWGetConnectionNumber(connHandle, &connNumber));
  59.     if (nwrc != 0x0000)
  60.       {  printf("\nNWGetConnectionNumber: failed %04x",nwrc);
  61.           getch(); exit(1);
  62.       }
  63.  
  64. } //initmainnwcalls
  65.  
  66. // checklpts
  67. void checklpts()
  68. { int loop, temp;
  69.   WORD nwrc;
  70.  
  71.   printf("\nOLD SETTINGS");
  72.   for (loop=0;loop<=MAXLPTPORTS;loop++)
  73.   { nwrc = (NWGetCaptureStatus(loop));
  74.     if (nwrc == 0x00ff)
  75.     { nwrc = NWGetCaptureFlags(loop,(NWCAPTURE_FLAGS1 NWFAR *)&capture1,(NWCAPTURE_FLAGS2 NWFAR *)&capture2);
  76.       if (nwrc == 0x0000)
  77.       { temp = loop;
  78.         ShowSettings(loop);
  79.       }
  80.     } // if
  81.   } // for
  82.   printf("\nNEW SETTINGS:");
  83.   capture1.flushCaptureTimeout = 6;
  84.   nwrc = NWSetCaptureFlags(connHandle,temp,(NWCAPTURE_FLAGS1 NWFAR *)&capture1);
  85.   nwrc = NWGetCaptureFlags(temp,(NWCAPTURE_FLAGS1 NWFAR *)&capture1,(NWCAPTURE_FLAGS2 NWFAR *)&capture2);
  86.   if (nwrc == 0x0000)
  87.     ShowSettings(loop);
  88. } //checklpts
  89.  
  90. // Show the current print settings
  91. void ShowSettings(int loop)
  92. {  int returncode;
  93.  
  94.     NWGetFileServerName(connHandle,(char NWFAR *)&servername);
  95.     printf("\nServer: %s",servername);
  96.     printf("\nCopies\tLines\tChars\tBanner Name");
  97.     printf("\n%d\t%d\t%d\t%s",capture1.numCopies,capture1.maxLines,capture1.maxChars,capture1.bannerText);
  98.     if (capture1.jobControlFlags && 0x80)
  99.       printf("\nBanner Disabled");
  100.     else
  101.       printf("\nBanner Enabled");
  102.     if (capture1.jobControlFlags & 0x08)
  103.       printf("\nForm Feed");
  104.     else
  105.       printf("\nNo Form Feed");
  106.     if (capture2.fileCaptureFlag)
  107.       printf("\nCapturing to a file");
  108.     else
  109.       if (capture2.printQueueFlag)
  110.         printf("\nLPT%d redirected to Queue = %s",loop,capture2.queueName);
  111.     if (capture1.jobControlFlags & 0x10)
  112.       printf("\nWill notify when finished.");
  113.     else
  114.       printf("\nWill not notify when finished.");
  115.     printf("\nTabs converted to %d spaces",capture1.tabSize);
  116.     if (capture1.flushCaptureTimeout == 0)
  117.       printf("\nTimeout Disabled");
  118.     else
  119.       printf("\nTimeout: %d seconds",capture1.flushCaptureTimeout);
  120.     printf("\nForm Type: %d",capture1.formType);
  121.     if (capture1.flushCaptureOnClose)
  122.       printf("\nAuto Endcap: Off");
  123.     else
  124.       printf("\nAuto Endcap: On");
  125. } // ShowSettings
  126.  
  127. // Get a list of available Print Queues
  128. void GetQueues(int servernum)
  129. {
  130.   char searchObjectName[48], objectName[48], buff[48], searchPropertyName[16], propertyName[16];
  131.   char propertyFlags, propertySecurity,propertyHasValue, moreProperties;
  132.   NWOBJ_TYPE searchObjectType, objectType, tmpType;
  133.   NWFLAGS hasPropertiesFlag, objectFlag, objectSecurity, objectHasProperties;
  134.   BYTE propertyValue[128], moreSegments, accessLevel;
  135.   NWOBJ_ID objectID = -1;
  136.   WORD connType, spxID;
  137.   DWORD connID;
  138.   int counter=0,loop, counter2=0;
  139.   char printservername[16][48];
  140.   NWNUM queueStartPosition;
  141.   QueueJobListReply job;
  142.  
  143. //  strcpy(searchObjectName,"*");
  144. //  searchObjectType = OT_PRINT_SERVER;
  145. //  while (! (NWScanObject(raj[servernum].yourconnHandle,searchObjectName,OT_PRINT_SERVER,
  146. //               &objectID,objectName,&objectType,&objectHasProperties,
  147. //               &objectFlag,&objectSecurity)))
  148. //  strcpy(raj[servernum].printserver[counter2++],objectName);
  149. //  raj[servernum].numberofprintservers = counter2 - 1;
  150. // next five lines can be // out
  151. //  printf("\n\nSERVER: %s",raj[servernum].servername);
  152. //  printf("\nPrint Servers:");
  153. //  for (loop=0;loop<counter2;loop++)
  154. //      printf("\n%s",raj[servernum].printserver[loop]);
  155.   printf("\n\nPrint Queues:");
  156.   strcpy(searchObjectName,"*");
  157.   searchObjectType = OT_PRINT_QUEUE;
  158.   while (! (NWScanObject(raj[servernum].yourconnHandle,searchObjectName,OT_PRINT_QUEUE,
  159.                &objectID,objectName,&objectType,&objectHasProperties,
  160.                &objectFlag,&objectSecurity)))
  161.   {  strcpy(raj[servernum].queuename[counter],objectName);
  162.      raj[servernum].queueid[counter++] = objectID;
  163.      if (SHOWONLY == YES)
  164.        printf("\n%d.\t%s",counter-1,objectName);
  165.   }
  166.   raj[servernum].numberofqueues = counter - 1;
  167. } // GetQueues
  168.  
  169. // scan the queue for print jobs
  170. void ScanQueues(int snum)
  171. { char username[48];
  172.   NWNUM queueStartPosition=1;
  173.   QueueJobListReply job;
  174.   NWQueueJobStruct job2;
  175.   int loop,loop2,loop3,temp;
  176.   static int prevjobnumber;
  177.   NWSIZE fileSize;
  178.   WORD nwrc;
  179.   FILE *tempfile;
  180.   NWOBJ_TYPE objectType;
  181.  
  182.   clrscr();
  183.   for (loop=0;loop<=raj[snum].numberofqueues;loop++)
  184.     {  gotoxy(1,1);
  185.        printf("\nScanning print queues on server %s for a print job. . .", raj[snum].servername);
  186. //        delay(500);
  187.        for(loop2=0;loop2<=raj[snum].numberofqueues;loop2++)
  188.          {  NWGetQueueJobList2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],queueStartPosition,(QueueJobListReply NWFAR *)&job);
  189.             if (job.totalQueueJobs != 0)
  190.               {  printf("\nServer: %s\tQueue: %s\t# of Jobs: %d",raj[snum].servername,raj[snum].queuename[loop2],job.totalQueueJobs);
  191.                  printf("\nPos #\tFile Size\tUser Name");
  192.                  for (loop3=0;loop3<job.totalQueueJobs;loop3++)
  193.                  if (prevjobnumber != job.jobNumberList[loop3])
  194.                    {  printf("\n%d",loop3);
  195.                       nwrc = NWGetQueueJobFileSize2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],job.jobNumberList[loop3],(NWSIZE NWFAR *)&fileSize);
  196.                       if (nwrc == 0x0000)
  197.                         printf("\t%ld",fileSize);
  198.                       else
  199.                         printf("\nFileSize failed: %04x",nwrc);
  200.                       nwrc = NWReadQueueJobEntry2(raj[snum].yourconnHandle,raj[snum].queueid[loop2],job.jobNumberList[loop3],(NWQueueJobStruct NWFAR *)&job2);
  201.                       if (nwrc == 0x0000)
  202.                         {  NWGetObjectName(raj[snum].yourconnHandle,job2.clientID,(char NWFAR *)&username,(NWOBJ_TYPE NWFAR *)&objectType);
  203.                            printf("\t\t%s",username);
  204.                         }
  205.                       else
  206.                         printf("\nJobEntry failed: %04x",nwrc);
  207.                       prevjobnumber = job.jobNumberList[loop3];
  208.                    delay(500);
  209.                  } // if
  210.               } // if
  211.          } // for
  212.     } // for
  213. } // ScanQueues
  214.  
  215. // scan the bindery for servers
  216. int scanforservers()
  217.  {  int binerror = 0, counter=0;
  218.     WORD nwrc;
  219.     char searchName[48], objectName[48];
  220.     NWOBJ_TYPE searchType = OT_FILE_SERVER, objectType;
  221.     NWOBJ_ID objectID = -1;
  222.     NWFLAGS hasPropertiesFlag, objectFlags, objectSecurity;
  223.  
  224.     strcpy(searchName,"*");
  225.     while (binerror == 0)
  226.       {
  227.      nwrc = (NWScanObject(connHandle, (char NWFAR *)searchName, searchType, (NWOBJ_ID NWFAR *)&objectID,
  228.         (char NWFAR *)&objectName, (NWOBJ_TYPE NWFAR *)&objectType, (NWFLAGS NWFAR *)&hasPropertiesFlag,
  229.         (NWFLAGS NWFAR *)&objectFlags, (NWFLAGS NWFAR *)&objectSecurity));
  230.      if (nwrc != 0x0000)
  231.        {  //printf("\nNWScanObject failed: %x",nwrc);
  232.            binerror = 1;   //getch(); exit(1);
  233.        }
  234.      else
  235.        {  binerror = 0;
  236.         strcpy(serverlist[counter].name,objectName);
  237.         counter++;
  238.        }
  239.    } // while
  240.   return(counter);
  241. } //scanforservers
  242.  
  243. // get information on a server
  244. int getserverinfo(servernum)
  245. {  int error = 0;  WORD nwrc;
  246.    VERSION_INFO fsinfotemp;
  247.    static unsigned int servercount;
  248.    NWCONN_HANDLE tempconnHandle;
  249.    int tempconnNumber;
  250.  
  251.    nwrc = (NWGetConnectionHandle((BYTE NWFAR *)&serverlist[servernum].name, 0,(NWCONN_HANDLE NWFAR *)&tempconnHandle, NULL));
  252.    if (nwrc != 0x0000)
  253.      {  // printf("\nNWGetConnectionHandle failed: %x",nwrc);
  254.     // getch(); exit(1);
  255.     error = 1;
  256.      }
  257.    if (error == 0)
  258.      {  nwrc = (NWGetConnectionNumber(tempconnHandle, &tempconnNumber));
  259.     if (nwrc != 0x0000)
  260.       {  printf("\nNWGetConnectionNumber failed: %x",nwrc);
  261.          exit(1);
  262.       }
  263.     nwrc = (NWGetFileServerVersionInfo(tempconnHandle, (VERSION_INFO FAR *)&fsinfotemp));
  264.     if (nwrc != 0x0000)
  265.       { printf("\nNWGetFileServerVersionInfo: failed %04x",nwrc);
  266.      exit(1);
  267.       }
  268.     strcpy(raj[maincounter].servername,fsinfotemp.serverName);
  269.     raj[maincounter].yourconnNumber = tempconnNumber;
  270.     raj[maincounter++].yourconnHandle = tempconnHandle;
  271.  
  272.     strcpy(serverinfo[servercount].name,fsinfotemp.serverName);
  273.     serverinfo[servercount].connsinuse = fsinfotemp.connectionsInUse;
  274.     serverinfo[servercount].yourconnNumber = tempconnNumber;
  275.     serverinfo[servercount].yourconnHandle = tempconnHandle;
  276.     servercount++;
  277.      }  //if error
  278.   return(servercount);
  279. } //getserverinfo
  280.  
  281. // Get connection info based on the connection number and connection handle
  282. void getconninfo(NWCONN_HANDLE chandle,NWCONN_NUM cnum)
  283. {  WORD nwrc;
  284.  
  285.     nwrc = NWGetConnectionInformation(chandle,cnum,(char NWFAR *)userinfo.objname,(WORD FAR *)&userinfo.objtype,(DWORD FAR *)&userinfo.objID,(BYTE FAR *)userinfo.logintime);
  286.     if (nwrc != 0x0000)
  287.       {  clrscr();
  288.          printf("NWGetConnectionInformation failed: %x",nwrc);
  289.          getch();
  290.       }
  291. } //getconninfo
  292.  
  293. void displayhelp()
  294. {
  295.   clrscr();
  296.   printf("\nFILE: PRINTQ.EXE");
  297.   printf("\n\nSyntax: printq [/? | /q]");
  298.   printf("\nThe /? option display this screen.");
  299.   printf("\nThe /q option will display all print queues that exist on the servers");
  300.   printf("\nyou are attached to.");
  301.   printf("\nNo option will show any print jobs that are currently in the queue.");
  302.   printf("\nIt will also display the owner of the job, job number, and size of the job.");
  303.   printf("\n\nNOTE: When no options are used, the program runs until you hit a key.");
  304. } // displayhelp
  305.  
  306.  
  307. // Close all open Windows
  308. void CloseAllWindows()
  309. { int loop;
  310.  
  311.   for(loop=wnum;loop==0;loop--)
  312.     CloseTopWindow(&buffer[loop]);
  313.   wnum=0;
  314. }
  315.